<?php



/**
 * 订单管理
 * Enter description here ...
 * @author Admin
 *
 */
class OrderAction extends CommonAction{

	
	/**
	 * 订单列表
	 * Enter description here ...
	 */
	public function index() {
		$data = Init_GP(array("start","end","name","aid","type"));  //检索条件
		
		$order = D('Order');
		if (!empty($data)){
			if (!empty($data['start']) && !empty($data['end']))	{
				$start_tmp = strtotime($data['start']);
				$end_tmp = strtotime($data['end']);
				$map['addtime']  = array('between',"{$start_tmp},{$end_tmp}");
			}
			if (!empty($data['name']))$map['name']=array('eq',$data['name']);
			if (!empty($data['aid']))$map['aid']=array('eq',$data['aid']);
			if ($data['type'] != "")$map['type']=array('eq',$data['type']);
		}
		
		
		import("@.ORG.Page"); //导入分页类
		$count = $order->where($map)->count();    //计算总数
		$p = new Page ($count,10);
		$orderdata=$order->where($map)->limit($p->firstRow.','.$p->listRows)->order('id desc')->findAll();
		//分页条件写入
		foreach($data as $key=>$val) {
			$p->parameter   .=   "$key=".$val."&";
		}
		
		$page = $p->show ();
		$this->assign("page",$page);
		$this->assign("orderdata",$orderdata);
		$this->assign('down',$p->parameter);
		
		if($data['type']==2)
			$this->display('indexm');  //商场订单
		
		else $this->display();
	}
	
	
	/**
	 * 下载数据
	 * Enter description here ...
	 */
	public function down(){
		$data = Init_GP(array("start","end","name","aid","state"));
		
		$order = D('Order');
		if (!empty($data)){
			if (!empty($data['start']) && !empty($data['end']))	{
				$start_tmp = strtotime($data['start']);
				$end_tmp = strtotime($data['end']);
				$map['addtime']  = array('between',"{$start_tmp},{$end_tmp}");
			}
			if (!empty($data['name']))$map['name']=array('eq',$data['name']);
			if (!empty($data['aid']))$map['aid']=array('eq',$data['aid']);
			if (!empty($data['state']))$map['state']=array('eq',$data['state']);
			
		}
		
		$orderdata=$order->where($map)->order('id desc')->findAll();
		
		$keynames = array(
			'id'=>'ID',
			'ordersn'=>'订单号',
			'aid'=>'竞拍ID',
			'name'=>'用户名',
			'goodsname'=>'商品名称',
			'orderprice'=>'订单价格',
			'address'=>'地址',
			'postalcode'=>'邮编',
			'tel'=>'联系方式',
			'type'=>'订单类型',
			'addtime'=>'添加时间',
			'state'=>'订单状态',
			'remark'=>'备注'
		);
		
		down_xls($orderdata, $keynames,'订单列表_'.date("Y-m-d"));
	}
	
	
	
	
	
	
	/**
	 * 设置订单为已付款
	 * Enter description here ...
	 */
	public function setPaid(){
		$order = D('Order');
		$id     = GetNum($_GET['id']);  //主键
		
		$map['id'] = array('eq',$id);
		if(FALSE === $order->where($map)->setField('state',1)){
            $this->error("操作失败");
        }else {
        	$this->success("操作成功");
        }
	}
	
	
	
	/**
	 * 设置订单为已成交
	 * Enter description here ...
	 */
	public function setExecuted(){
		$order = D('Order');
		$id     = GetNum($_GET['id']);  //主键
		
		$map['id'] = array('eq',$id);
		if(FALSE === $order->where($map)->setField('state',3)){
            $this->error("操作失败");
        }else {
        	$this->success("操作成功");
        }
	}
	
	
	
	
	
	
	
	public function add(){
		$this->error('操作错误');
	}
	
	public function del(){
		$this->error('操作错误');
	}
	
	public function dels(){
		$this->error('操作错误');
	}
	
	public function insert(){
		$this->error('操作错误');
	}
	
	public function update(){
		$this->error('操作错误');
	}
}
?>